import { Row,Col,Alert} from 'antd';
import { inject, observer} from 'mobx-react';
import {WeaTab,WeaTop,WeaAlertPage,WeaLocaleProvider} from 'ecCom'
import AddCard from './AddCard';
const getLabel = WeaLocaleProvider.getLabel;

let sb = '';
@inject("topStore")
@observer
export default class TopList extends React.Component {

	constructor(props) {
		super(props);
		sb = this;
	}

    componentDidMount() {
        const {topStore} = this.props;
        topStore.initDatas({"needall":"1","hasStruct":true});
        this.scrollheigth();
	}
    componentDidUpdate = () => {
        this.scrollheigth();
    }
	componentWillReceiveProps(nextProps) {
        const keyOld = this.props.location.key;
        const keyNew = nextProps.location.key;
        if(keyOld!==keyNew) {
            const {topStore} = nextProps;
            topStore.initDatas({"needall":"1","hasStruct":true});
			topStore.setSearchValue("");
			this.scrollheigth();
        }
    }
    componentWillUnmount(){
		//记录上次打开的模式
		const {topStore} = this.props;
		topStore.setSearchValue("");
    }
    scrollheigth(){
    	let top = jQuery(".g-topList-add").offset() ? (jQuery(".g-topList-add").offset().top ? jQuery(".g-topList-add").offset().top : 0) : 0;
        let scrollheigth = document.documentElement.clientHeight - top;
        jQuery(".g-topList-add").height(scrollheigth-30);
    }

    getMessage=(isRight)=>{
        if(isRight){
            return(<Alert ecId={`${this && this.props && this.props.ecId || ''}_Alert@akmr1f`} message={getLabel(558,"提示")} description={getLabel(509936 ,"请联系管理员在后台赋予督办类型的新建权限")} type="info" showIcon /> )
        }else{
            return(<Alert ecId={`${this && this.props && this.props.ecId || ''}_Alert@dtmsrt`} message={getLabel(558,"提示")} description={getLabel(385021,"数据为空")} type="info" showIcon />)
        }
    }
    render() {
        const {topStore} = this.props;
        const {showDatas = {}, value,tabkey,loading,importDataShow,wfOperateInfo,getActionSetting,loaded,isRight} = topStore;
        const {typesShow,typesCols} = showDatas;
        const {importWf,doAddWfToColl,createwflabels = {},tabDatas = [],typeData = []} = topStore;
        const actions  = {importWf,doAddWfToColl};
        const {toplabel = "",topIcon="icon-coms-government" ,iconBgcolor="#f14a2d"} = createwflabels;
        // if (loaded && isRight) {
        //     return (<WeaAlertPage >
        //         <div style={{ color: '#000' }}>
        //             {getLabel(2012, "对不起，您暂时没有权限！")}
        //         </div>
        //     </WeaAlertPage>
        //     )
        // }
     
        return (
            <div className = "g-top">
            <div className="g-top-topList">
                <div className="g-topList-main">
                        {/* 督办立项 */}
                         <WeaTop ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@jjsyh8`} loading={loading} icon={<i className={topIcon} />} iconBgcolor={iconBgcolor} title={toplabel} />
                        {/* 全部流程 */}
                        <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@yuisb8`}
                        onSearchChange={this.doSearch.bind(this)}
                        searchsBaseValue={value}
                        selectedKey={tabkey}
                        datas={tabDatas}
                        searchType={["base"]}
                        keyParam='key'
                        onChange={this.changeTab.bind(this)}
                        />
                        {/* card集 */}
                        <div className="g-topList-add">
                            {
                                typesShow.length == 0 && !loading ? this.getMessage(isRight) : (
                                        <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@1r3wio`}>
                                            {typesCols.map(c=>{
                                                return <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@mwuusu@${c.id}`} span={24 / typesCols.length} style={{padding:'0 10px'}}>
                                                <AddCard ecId={`${this && this.props && this.props.ecId || ''}_AddCard@6sz8fc@${c.id}`} types={c} actions={actions} openModal={getActionSetting}/>
                                            </Col>
                                            })}
                                        </Row>
                                )
                            }
                        </div>
                </div>
            </div>
            </div>
        )
    }
    doSearch(v){
		const {topStore} = this.props;
		topStore.setSearchValue(v);
		jQuery(".g-topList-add").scrollTop(0);
    }
    changeTab(k){
		const {topStore} = this.props;
        topStore.changeTab(k);
        jQuery(".g-topList-add").scrollTop(0);
	}
}
/* jQuery(window).resize(function() {
    sb && sb.props && sb.props.topStore && sb.props.topStore.setUpdate();
}); */
